package com.inossem.warehousestorage_inossem.utils;

import android.text.TextUtils;

import com.inossem.utils.base.ArithUtils;
import com.inossem.warehousestorage_inossem.adapter.OverviewAdapter;
import com.inossem.warehousestorage_inossem.bean.receive.ReceiveReceiveItemBean;
import com.inossem.warehousestorage_inossem.bean.storage.StorageManageMatrBean;
import com.inossem.warehousestorage_inossem.bean.storage.StorageManageMatrCommitBean;
import com.inossem.warehousestorage_inossem.bean.up_frame.UpFrameItemBean;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2017/9/23 0023.
 */

public class StorageManageUtils {
    public static double getUpCount(StorageManageMatrBean information) {
        double ret = 0;
        for (StorageManageMatrBean.DataBean.MaterielListBean m : information.getData().getMaterielList()) {
            ret = ret + getUpCount(m);
        }
        return ret;
    }

    public static StorageManageMatrCommitBean getCommitBean(StorageManageMatrBean information) {
        List<StorageManageMatrBean.DataBean.MaterielListBean> ml = information.getData().getMaterielList();
        StorageManageMatrCommitBean ret = new StorageManageMatrCommitBean();
        for (StorageManageMatrBean.DataBean.MaterielListBean m : ml) {
            List<UpFrameItemBean.DataBean.ListBean> ul = m.getUpList();
            if (ul.size() > 0) {
                StorageManageMatrCommitBean.DataBean.MaterielListBean rm = new StorageManageMatrCommitBean.DataBean.MaterielListBean();
                rm.setSendPosition(m.getSendPosition());
                rm.setBatchCode(m.getBatchCode());
                rm.setMaterielCode(m.getMaterielCode());
                rm.setLqnum(m.getLqnum());
                ret.getData().getMaterielList().add(rm);
                for (UpFrameItemBean.DataBean.ListBean u : ul) {
                    StorageManageMatrCommitBean.DataBean.MaterielListBean.ReceivePositionListBean p = new StorageManageMatrCommitBean.DataBean.MaterielListBean.ReceivePositionListBean();
                    p.setReceivePosition(u.getPosition());
                    p.setNumber(u.getNumber());
                    rm.getReceivePositionList().add(p);
                }
            }

        }
        return ret;
    }

    public static double getUpCount(StorageManageMatrBean.DataBean.MaterielListBean item) {
        BigDecimal ret = new BigDecimal(0);
        for (int i = 0; i < item.getUpList().size(); i++) {
            String number = item.getUpList().get(i).getNumber();
            ret = ArithUtils.add(ret.toString(), number);
        }
        return ret.doubleValue();
    }

    public static List<OverviewAdapter.OverviewBean> getOverViewList(StorageManageMatrBean bean) {
        List<OverviewAdapter.OverviewBean> resultList = new ArrayList<>();
        for (int i = 0; i < bean.getData().getMaterielList().size(); i++) {
            StorageManageMatrBean.DataBean.MaterielListBean materielItem = bean.getData().getMaterielList().get(i);
            double upCount = getUpCount(materielItem);
            if(upCount>0){
                OverviewAdapter.OverviewBean overItem = new OverviewAdapter.OverviewBean();
                overItem.setInfo(materielItem.getMaterielDescription());
                overItem.setNumber(upCount + materielItem.getUnit());
                resultList.add(overItem);
            }
        }
        return resultList;
    }
}
